#One big function to be made

def TMA(A, f):
    n = len(A)

    #upper coefficients
    c = []; d = []

    c.append(A[0][1]/A[0][0])

    for i in range(1,n-1):
        c.append(A[i][i+1]/(A[i][i]-c[i-1]*A[i][i-1]))

    #free vector
    d.append(f[0]/A[0][0])

    for i in range(1,n):
        d.append((f[i]-d[i-1]*A[i][i-1])/\
        (A[i][i]-c[i-1]*A[i][i-1]))

    y = [0 for i in range(n)]

    y[n-1] = d[n-1]

    for i in range(2, n+1):
        y[n-i] = d[n-i] - c[n-i]*y[n-i+1]

    return y 
